package com.ruoyi.web.controller.sj.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.sj.domain.Money;
import com.ruoyi.sj.service.IMoneyService;
import com.ruoyi.web.core.base.BaseController;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.common.base.AjaxResult;

/**
 * 零钱 信息操作处理
 * 
 * @author ruoyi
 * @date 2018-11-28
 */
@Controller
@RequestMapping("/sj/money")
public class MoneyController extends BaseController
{
    private String prefix = "sj/money";
	
	@Autowired
	private IMoneyService moneyService;
	
	@RequiresPermissions("sj:money:view")
	@GetMapping()
	public String money()
	{
	    return prefix + "/money";
	}
	
	/**
	 * 查询零钱列表
	 */
	@RequiresPermissions("sj:money:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(Money money)
	{
		startPage();
        List<Money> list = moneyService.selectMoneyList(money);
		return getDataTable(list);
	}
	
	/**
	 * 新增零钱
	 */
	@GetMapping("/add")
	public String add()
	{
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存零钱
	 */
	@RequiresPermissions("sj:money:add")
	@Log(title = "零钱", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(Money money)
	{		
		return toAjax(moneyService.insertMoney(money));
	}

	/**
	 * 修改零钱
	 */
	@GetMapping("/edit/{id}")
	public String edit(@PathVariable("id") Long id, ModelMap mmap)
	{
		Money money = moneyService.selectMoneyById(id);
		mmap.put("money", money);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存零钱
	 */
	@RequiresPermissions("sj:money:edit")
	@Log(title = "零钱", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(Money money)
	{		
		return toAjax(moneyService.updateMoney(money));
	}
	
	/**
	 * 删除零钱
	 */
	@RequiresPermissions("sj:money:remove")
	@Log(title = "零钱", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(moneyService.deleteMoneyByIds(ids));
	}
	
}
